package jmine.tec.batch.export;

import java.util.LinkedList;
import java.util.List;

import jmine.tec.batch.domain.MPhase;
import jmine.tec.batch.services.MPhaseService;
import jmine.tec.services.api.export.AbstractServiceFillerEntityExporter;
import jmine.tec.services.api.export.DefaultExportAction;

/**
 * Exporter da entidade {@link MPhase}.
 * 
 * @author Rafael Volpato
 * @date Nov 3, 2009
 */
public class MPhaseExporter extends AbstractServiceFillerEntityExporter<MPhase> {

    /**
     * Construtor.
     */
    public MPhaseExporter() {
        super(new MPhaseService(), DefaultExportAction.INCLUIR);
    }

    /**
     * Marcar para exportação todas dependencias da {@link MPhase} que esta sendo exportada ({@link MPhase} e MProcess).
     * 
     * @param entity {@link MPhase}
     * @return lista contendo todas as {@link MPhase} e MProcess associados a {@link MPhase} exportada.
     */
    @Override
    public List<Object> exportBefore(MPhase entity) {
        List<Object> result = new LinkedList<Object>(super.exportBefore(entity));

        result.addAll(entity.getDependencies());
        result.addAll(entity.getProcesses());

        return result;
    }

    /**
     * Marca para exportação a dependencia entre {@link MPhase}.
     * 
     * @param entity {@link MPhase}
     * @return lista contendo a dependencia entre {@link MPhase}
     */
    @Override
    public List<Object> exportAfter(MPhase entity) {
        List<Object> result = new LinkedList<Object>(super.exportAfter(entity));

        for (MPhase phase : entity.getDependencies()) {
            result.add(new MPhaseDependencyAssociation(entity, phase));
        }

        return result;
    }
}
